package com.wanmait.gohome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.gohome.mapper.NewsMapper;
import com.wanmait.gohome.pojo.News;
import com.wanmait.gohome.service.NewsService;
import com.wanmait.gohome.util.SysContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class NewsServiceImpl implements NewsService
{
    @Resource
    private NewsMapper newsMapper;
    //后台添加方法
    @Override
    public void insert(News object) {

    }

    @Override
    public void update(Integer id) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public List<News> findAll() {
        return null;
    }

    @Override
    public News findById(Integer id) {
        return newsMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<News> findPage() {
        return null;
    }

    @Override
    public List<News> findAll(News object) {
        return null;
    }

    @Override
    public PageInfo<News> findPage(News object) {
        return null;
    }

    @Override
    public PageInfo<News> selectAll() {
        int pageNum=SysContext.getPageNum();
        int pageSize=10;
        try {
            //pageSize = Integer.parseInt();//数据库里取
        } catch (NumberFormatException e) {
            pageSize=10;
        }
        PageHelper.startPage(pageNum,pageSize);//pageSize
        List<News> news = newsMapper.selectAll();
        PageInfo<News> newsPageInfo = new PageInfo<>(news,5);
        return newsPageInfo;
    }
//后台添加方法
    @Override
    public void add(News news) {
        newsMapper.insertSelective(news);
    }

    @Override
    public void deleteNews(Integer id) {
        newsMapper.deleteNews(id);
    }

    @Override
    public void updateNews(News news) {
        newsMapper.updateNews(news);
    }


}
